/*
 * @Descripttion: 
 * @version: 
 * @Author: hejin.gao
 * @Date: 2021-12-29 14:02:15
 * @LastEditors: hejin.gao
 * @LastEditTime: 2022-01-07 17:47:03
 */

import { showPickArea } from './draw/areaMeasure';
import { showSpaceDistance } from './draw/spaceDistance';
import { showStickDistance } from './draw/stickDistance';

/* eslint-disable */
export default class PlotManager {

    constructor(viewer, layerId = "drawHelper") {
        this._viewer = viewer;
        this._handler = new Cesium.ScreenSpaceEventHandler(this._viewer.scene.canvas);
        this._entities = [];
        this._show = true;

        //图层名称
        this._layerId = layerId;

        /**
         * 全局变量，用来记录shape坐标信息
         * id       唯一紡号
         * type     标绘类型
         * position 点位
         * positions点位数组
         * custom   箭头规则
         * radius
         */
        this._shapeDic = {};

        //编辑或删除标识,1为编辑，2为删除
        this._flag = 0;

        // 标绘对象
        this._tracker = new GlobeTracker(this._viewer);
        this._showMananger = new ShowManager(this._viewer)

        this.bindGloveEvent()
    }

    clear() {
        this._flag = 0;
        this._tracker && this._tracker.clear();
    }
    destroy() {
        this.clear();
        this.clearAllEntity();
        this._tracker = null;
        this._handler && this._handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
        this._handler = null;
    }
    flyTo() {
        if (!this._entities || this._entities.length < 1) { return; }
        this._viewer.flyTo(this._entities);
    }
    // 删除标绘
    clearEntityById(objId) {
        if (!this._entities || this._entities.length < 1) {
            return;
        }
        for (var i = 0; i < this._entities.length; i++) {
            var entity = this._entities[i];
            if (entity.layerId == this._layerId && entity.objId == objId) {
                this._viewer.entities.remove(entity);
                this._entities.splice(i, 1);
                i--;
            }
        }
    }
    // 清除标绘
    clearAllEntity() {
        if (!this._entities || this._entities.length < 1) {
            return;
        }
        this._entities.map(entity => {
            this._viewer.entities.remove(entity);
        })
        this._entities.length = 0;
    }
    get shapeDic() {
        return this._shapeDic;
    }
    get show() {
        return this._show;
    }
    set show(bool) {
        this._show = bool;
        this._entities.map(entity => {
            entity.show = bool;
        })
    }

    //绑定cesium事件
    bindGloveEvent() {
        let me = this;
        this._handler = new Cesium.ScreenSpaceEventHandler(me._viewer.scene.canvas);
        this._handler.setInputAction(function (movement) {
            var pick = me._viewer.scene.pick(movement.position);
            if (!pick) {
                return;
            }
            var obj = pick.id;
            if (!obj || !obj.layerId || me._flag == 0) {
                return;
            }

            var objId = obj.objId;
            // flag为编辑或删除标识, 1为编辑, 2为删除
            if (me._flag == 1) {
                switch (obj.shapeType) {
                    case "Polygon":
                        me._flag = 0;
                        me.editPolygon(objId);
                        break;
                    case "Polyline":
                        me._flag = 0;
                        me.editPolyline(objId);
                        break;
                    case "Rectangle":
                        me._flag = 0;
                        me.editRectangle(objId);
                        break;
                    case "Circle":
                        me._flag = 0;
                        me.editCircle(objId);
                        break;
                    case "Point":
                        me._flag = 0;
                        me.editPoint(objId);
                        break;
                    case "BufferLine":
                        me._flag = 0;
                        me.editBufferLine(objId);
                        break;
                    case "PosMeasure":
                        me._flag = 0;
                        me.editPosMeasure(objId);
                        break;
                    case "SpaceDistance":
                        me._flag = 0;
                        me.editSpaceDistance(objId);
                        break;
                    case "StickDistance":
                        me._flag = 0;
                        me.editStickDistance(objId);
                        break;
                    case "AreaMeasure":
                        me._flag = 0;
                        me.editAreaMeasure(objId);
                        break;
                    case "StraightArrow":
                        me._flag = 0;
                        me.editStraightArrow(objId);
                        break;
                    case "AttackArrow":
                        me._flag = 0;
                        me.editAttackArrow(objId);
                        break;
                    case "PincerArrow":
                        me._flag = 0;
                        me.editPincerArrow(objId);
                        break;
                    default:
                        break;
                }
            } else if (me._flag == 2) {
                me.clearEntityById(objId);
            }
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    }
    // 创建标绘
    draw(feature) {
        let me = this;
        let objId = (new Date()).getTime();
        let tmp = { id: objId, type: feature.type, position: null, positions: null, custom: null, radius: null }
        return new Promise((resole, reject) => {
            switch (feature.type) {
                case 'POLYGON':
                    me._flag = 0;
                    me._tracker.trackPolygon(function (positions) {
                        me._shapeDic[objId] = Object.assign(tmp, { positions: positions });
                        me._entities.push(me._showMananger.showPolygon(me._layerId, objId, positions));
                        resole(feature.id);
                    }, function () {
                        resole(feature.id);
                    });
                    break;
                case 'POLYLINE':
                    me._flag = 0;
                    me._tracker.trackPolyline(function (positions) {
                        me._shapeDic[objId] = Object.assign(tmp, { positions: positions });
                        me._entities.push(me._showMananger.showPolyline(me._layerId, objId, positions));
                        resole(feature.id);
                    }, function () {
                        resole(feature.id);
                    });
                    break;
                case 'RECTANGLE':
                    me._flag = 0;
                    me._tracker.trackRectangle(function (positions) {
                        me._shapeDic[objId] = Object.assign(tmp, { positions: positions });
                        me._entities.push(me._showMananger.showRectangle(me._layerId, objId, positions));
                        resole(feature.id);
                    }, function () {
                        resole(feature.id);
                    });
                    break;
                case 'CIRCLE':
                    me._flag = 0;
                    me._tracker.trackCircle(function (positions) {
                        me._shapeDic[objId] = Object.assign(tmp, { positions: positions });
                        me._entities.push(me._showMananger.showCircle(me._layerId, objId, positions, me._tracker));
                        resole(feature.id);
                    }, function () {
                        resole(feature.id);
                    });
                    break;
                case 'POINT':
                    me._flag = 0;
                    me._tracker.trackPoint(function (position, lonLat, text) {
                        me._shapeDic[objId] = Object.assign(tmp, { position: position, text });
                        me._entities.push(me._showMananger.showPoint(me._layerId, objId, position, text));
                        resole(feature.id);
                    }, function () {
                        resole(feature.id);
                    });
                    break;
                case 'BUFFERLINE':
                    me._flag = 0;
                    me._tracker.trackBufferLine(function (positions, radius) {
                        let objId = (new Date()).getTime();
                        me._shapeDic[objId] = Object.assign(tmp, {
                            positions: positions,
                            radius: radius
                        });
                        me._entities.push(me._showMananger.showBufferLine(me._layerId, objId, positions, radius, me._tracker));
                        resole(feature.id);
                    }, function () {
                        resole(feature.id);
                    });
                    break;
                case 'POSMEASURE':
                    me._flag = 0;
                    me._tracker.pickPosition(function (positions, lonLat) {
                        me._shapeDic[objId] = Object.assign(tmp, { positions: positions });
                        me._entities.push(me._showMananger.showPosDistance(me._layerId, objId, positions));
                        resole(feature.id);
                    }, function () {
                        resole(feature.id);
                    });
                    break;
                case 'SPACEDISMEASURE':
                    me._flag = 0;
                    me._tracker.pickSpaceDistance(function (positions, rlt) {
                        me._shapeDic[objId] = Object.assign(tmp, { positions: positions });
                        me._entities.push(showSpaceDistance(me._viewer, me._layerId, objId, positions));
                        resole(feature.id);
                    }, function () {
                        resole(feature.id);
                    });
                    break;
                case 'STICKDISMEASURE':
                    me._flag = 0;
                    me._tracker.pickStickDistance(function (positions, rlt) {
                        me._shapeDic[objId] = Object.assign(tmp, { positions: positions });
                        me._entities.push(showStickDistance(me._viewer, me._layerId, objId, positions));
                        resole(feature.id);
                    }, function () {
                        resole(feature.id);
                    });
                    break;
                case 'AREAMEASURE':
                    me._flag = 0;
                    me._tracker.pickArea(function (positions, rlt) {
                        me._shapeDic[objId] = Object.assign(tmp, { positions: positions });
                        me._entities.push(showPickArea(me._viewer, me._layerId, objId, positions));
                        resole(feature.id);
                    }, function () {
                        resole(feature.id);
                    });
                    break;

                case 'STRAIGHTARROW':
                    me._flag = 0;
                    me._tracker.trackStraightArrow(function (positions) {
                        me._shapeDic[objId] = Object.assign(tmp, { positions: positions });
                        me._entities.push(me._showMananger.showStraightArrow(me._layerId, objId, positions));
                        resole(feature.id);
                    }, function () {
                        resole(feature.id);
                    });
                    break;
                case 'ATTACKARROW':
                    me._flag = 0;
                    me._tracker.trackAttackArrow(function (positions, custom) {
                        me._shapeDic[objId] = Object.assign(tmp, {
                            positions: positions,
                            custom: custom
                        });
                        me._entities.push(me._showMananger.showAttackArrow(me._layerId, objId, positions));
                        resole(feature.id);
                    }, function () {
                        resole(feature.id);
                    });
                    break;
                case 'PINCERARROW':
                    me._flag = 0;
                    me._tracker.trackPincerArrow(function (positions, custom) {
                        me._shapeDic[objId] = Object.assign(tmp, {
                            positions: positions,
                            custom: custom
                        });
                        me._entities.push(me._showMananger.showPincerArrow(me._layerId, objId, positions));
                        resole(feature.id);
                    }, function () {
                        resole(feature.id);
                    });
                    break;
                case 'EDIT':
                    me._flag = 1;
                    me._tracker.clear();
                    // message.info('请点击要编辑的图形');
                    break;
                case 'DELETE':
                    me._flag = 2;
                    me._tracker.clear();
                    // message.info('请点击要删除的图形');
                    break;
                default:
                    return true;
            }
        })
    }
    // 导入标绘功能
    showShapeDic(shapeDic) {
        let me = this;
        me._shapeDic = shapeDic;
        let values = Object.values(shapeDic);
        return new Promise((resole, reject) => {
            values.map(feature => {
                switch (feature.type) {
                    case 'POLYGON':
                        me._entities.push(me._showMananger.showPolygon(me._layerId, feature.id, feature.positions));
                        break;
                    case 'POLYLINE':
                        me._entities.push(me._showMananger.showPolyline(me._layerId, feature.id, feature.positions));
                        break;
                    case 'RECTANGLE':
                        me._entities.push(me._showMananger.showRectangle(me._layerId, feature.id, feature.positions));
                        break;
                    case 'CIRCLE':
                        me._entities.push(me._showMananger.showCircle(me._layerId, feature.id, feature.positions, me._tracker));
                        break;
                    case 'POINT':
                        me._entities.push(me._showMananger.showPoint(me._layerId, feature.id, feature.position, feature.text));
                        break;
                    case 'BUFFERLINE':
                        me._entities.push(me._showMananger.showBufferLine(me._layerId, feature.id, feature.positions, feature.radius, me._tracker));
                        break;
                    case 'POSMEASURE':
                        me._entities.push(me._showMananger.showPosDistance(me._layerId, feature.id, feature.positions));
                        break;
                    case 'SPACEDISMEASURE':
                        me._entities.push(showSpaceDistance(me._viewer, me._layerId, feature.id, feature.positions));
                        break;
                    case 'STICKDISMEASURE':
                        me._entities.push(showStickDistance(me._viewer, me._layerId, feature.id, feature.positions));
                        break;
                    case 'AREAMEASURE':
                        me._entities.push(showPickArea(me._viewer, me._layerId, feature.id, feature.positions));
                        break;
                    case 'STRAIGHTARROW':
                        me._entities.push(me._showMananger.showStraightArrow(me._layerId, feature.id, feature.positions));
                        break;
                    case 'ATTACKARROW':
                        me._entities.push(me._showMananger.showAttackArrow(me._layerId, feature.id, feature.positions));
                        break;
                    case 'PINCERARROW':
                        me._entities.push(me._showMananger.showPincerArrow(me._layerId, feature.id, feature.positions));
                        break;
                }
            })
            resole(true);
        })
    }
    editPolygon(objId) {
        let me = this;
        var oldPositions = me._shapeDic[objId].positions;

        //先移除entity
        me.clearEntityById(objId);

        //进入编辑状态  
        me._tracker.polygonDrawer.showModifyPolygon(oldPositions, function (positions) {
            me._shapeDic[objId].positions = positions;
            me._entities.push(me._showMananger.showPolygon(me._layerId, objId, positions));
            me._flag = 1;
        }, function () {
            me._entities.push(me._showMananger.showPolygon(me._layerId, objId, oldPositions));
            me._flag = 1;
        });
    }
    editPolyline(objId) {
        let me = this;
        var oldPositions = me._shapeDic[objId].positions;

        //先移除entity
        me.clearEntityById(objId);;

        //进入编辑状态  
        me._tracker.polylineDrawer.showModifyPolyline(oldPositions, function (positions) {
            me._shapeDic[objId].positions = positions;
            me._entities.push(me._showMananger.showPolyline(me._layerId, objId, positions));
            me._flag = 1;
        }, function () {
            me._entities.push(me._showMananger.showPolyline(me._layerId, objId, oldPositions));
            me._flag = 1;
        });
    }
    editRectangle(objId) {
        let me = this;
        var oldPositions = JSON.parse(JSON.stringify(me._shapeDic[objId])).positions;
        //先移除entity
        me.clearEntityById(objId);;

        //进入编辑状态  
        me._tracker.rectDrawer.showModifyRectangle(oldPositions, function (positions) {
            me._shapeDic[objId].positions = positions;
            me._entities.push(me._showMananger.showRectangle(me._layerId, objId, positions));
            me._flag = 1;
        }, function () {
            let tempPositions = JSON.parse(JSON.stringify(me._shapeDic[objId])).positions;
            me._entities.push(me._showMananger.showRectangle(me._layerId, objId, tempPositions));
            me._flag = 1;
        });
    }
    editCircle(objId) {
        let me = this;
        var oldPositions = JSON.parse(JSON.stringify(me._shapeDic[objId])).positions;

        //先移除entity
        me.clearEntityById(objId);;

        //进入编辑状态  
        me._tracker.circleDrawer.showModifyCircle(oldPositions, function (positions) {
            me._shapeDic[objId].positions = positions;
            me._entities.push(me._showMananger.showCircle(me._layerId, objId, positions, me._tracker));
            me._flag = 1;
        }, function () {
            let tempPositions = JSON.parse(JSON.stringify(me._shapeDic[objId])).positions;
            me._entities.push(me._showMananger.showCircle(me._layerId, objId, tempPositions, me._tracker));
            me._flag = 1;
        });
    }
    editPoint(objId) {
        let me = this;
        // var oldPosition = me._shapeDic[objId].position;
        var old = me._shapeDic[objId];

        //先移除entity
        me.clearEntityById(objId);;

        //进入编辑状态  
        me._tracker.pointDrawer.showModifyPoint(old.position, old.text, function (position, lonLat, text) {
            me._shapeDic[objId] = {
                position,
                text
            };
            me._entities.push(me._showMananger.showPoint(me._layerId, objId, position, text));
            me._flag = 1;
        }, function () {
            me._entities.push(me._showMananger.showPoint(me._layerId, objId, old.position, old.text));
            me._flag = 1;
        });
    }
    editBufferLine(objId) {
        let me = this;
        var old = me._shapeDic[objId];

        //先移除entity
        me.clearEntityById(objId);

        //进入编辑状态  
        me._tracker.bufferLineDrawer.showModifyBufferLine(old.positions, old.radius, function (positions, radius) {
            me._shapeDic[objId] = {
                positions: positions,
                radius: radius
            };
            me._entities.push(me._showMananger.showBufferLine(me._layerId, objId, positions, radius, me._tracker));
            me._flag = 1;
        }, function () {
            me._entities.push(me._showMananger.showBufferLine(me._layerId, objId, old.positions, old.radius, me._tracker));
            me._flag = 1;
        });
    }
    editPosMeasure(objId) {
        let me = this;
        var oldPosition = me._shapeDic[objId].positions;

        //先移除entity
        me.clearEntityById(objId);;

        //进入编辑状态  
        me._tracker.posMeasure.showModifyPoint(oldPosition, function (position) {
            me._shapeDic[objId].position = position;
            me._entities.push(me._showMananger.showPosDistance(me._layerId, objId, position));
            me._flag = 1;
        }, function () {
            me._entities.push(me._showMananger.showPosDistance(me._layerId, objId, oldPosition));
            me._flag = 1;
        });
    }
    editSpaceDistance(objId) {
        let me = this;
        var oldPositions = me._shapeDic[objId].positions;

        //先移除entity
        me.clearEntityById(objId);

        //进入编辑状态  
        me._tracker.spaceDisMeasure.showModifyPolyline(oldPositions, function (positions) {
            me._shapeDic[objId].positions = positions;
            me._entities.push(showSpaceDistance(me._viewer, me._layerId, objId, positions));
            me._flag = 1;
        }, function () {
            me._entities.push(showSpaceDistance(me._viewer, me._layerId, objId, oldPositions));
            me._flag = 1;
        });
    }
    editStickDistance(objId) {
        let me = this;
        var oldPositions = me._shapeDic[objId].positions;

        //先移除entity
        me.clearEntityById(objId);;

        //进入编辑状态  
        me._tracker.stickDisMeasure.showModifyPolyline(oldPositions, function (positions) {
            me._shapeDic[objId].positions = positions;
            me._entities.push(showStickDistance(me._viewer, me._layerId, objId, positions));
            me._flag = 1;
        }, function () {
            me._entities.push(showStickDistance(me._viewer, me._layerId, objId, oldPositions));
            me._flag = 1;
        });
    }
    editAreaMeasure(objId) {
        let me = this;
        var oldPositions = me._shapeDic[objId].positions;
        //先移除entity
        me.clearEntityById(objId);

        me._tracker.areaMeasure.showModifyPolygon(oldPositions, function (positions) {
            me._shapeDic[objId].positions = positions;
            me._entities.push(showPickArea(me._viewer, me._layerId, objId, positions));
            me._flag = 1;
        }, function () {
            me._entities.push(showPickArea(me._viewer, me._layerId, objId, oldPositions));
            me._flag = 1;
        });
    }
    editStraightArrow(objId) {
        let me = this;
        var oldPositions = me._shapeDic[objId].positions;

        //先移除entity
        me.clearEntityById(objId);;

        //进入编辑状态  
        me._tracker.straightArrowDrawer.showModifyStraightArrow(oldPositions, function (positions) {
            me._shapeDic[objId].positions = positions;
            me._entities.push(me._showMananger.showStraightArrow(me._layerId, objId, positions));
            me._flag = 1;
        }, function () {
            me._entities.push(me._showMananger.showStraightArrow(me._layerId, objId, oldPositions));
            me._flag = 1;
        });
    }
    editAttackArrow(objId) {
        let me = this;
        var old = me._shapeDic[objId];

        //先移除entity
        me.clearEntityById(objId);;

        me._tracker.attackArrowDrawer.showModifyAttackArrow(old.custom, function (positions, custom) {
            //保存编辑结果
            me._shapeDic[objId] = {
                custom: custom,
                positions: positions
            };
            me._entities.push(me._showMananger.showAttackArrow(me._layerId, objId, positions));
            me._flag = 1;
        }, function () {
            me._entities.push(me._showMananger.showAttackArrow(me._layerId, objId, old.positions));
            me._flag = 1;
        });
    }
    editPincerArrow(objId) {
        let me = this;
        var old = me._shapeDic[objId];

        //先移除entity
        me.clearEntityById(objId);;

        me._tracker.pincerArrowDrawer.showModifyPincerArrow(old.custom, function (positions, custom) {
            //保存编辑结果
            me._shapeDic[objId] = {
                custom: custom,
                positions: positions
            };
            me._entities.push(me._showMananger.showPincerArrow(me._layerId, objId, positions));
            me._flag = 1;
        }, function () {
            me._entities.push(me._showMananger.showPincerArrow(me._layerId, objId, old.positions));
            me._flag = 1;
        });
    }
}

// cesium创建实体
class ShowManager {
    constructor(viewer) {
        this._viewer = viewer;
    }
    // 多边形
    showPolygon(layerId, objId, positions) {
        var material = plotting.fullColor;
        var outlineMaterial = new Cesium.PolylineDashMaterialProperty({
            dashLength: 16,
            color: plotting.lineColor
        });
        var outlinePositions = [].concat(positions);
        outlinePositions.push(positions[0]);
        var bData = {
            layerId: layerId,
            objId: objId,
            shapeType: "Polygon",
            polyline: {
                positions: outlinePositions,
                clampToGround: true,
                width: 2,
                material: outlineMaterial
            },
            polygon: new Cesium.PolygonGraphics({
                hierarchy: positions,
                asynchronous: false,
                material: material
            })
        };
        return viewer.entities.add(bData);
    }
    // 折线
    showPolyline(layerId, objId, positions) {
        var material = new Cesium.PolylineGlowMaterialProperty({
            glowPower: 0.25,
            // color: Cesium.Color.fromCssColorString(plotBgColor).withAlpha(0.9)
            color: plotting.fullColor
        });
        var bData = {
            layerId: layerId,
            objId: objId,
            shapeType: "Polyline",
            polyline: {
                positions: positions,
                clampToGround: true,
                width: 8,
                material: material
            }
        };
        return viewer.entities.add(bData);
    }
    // 矩形
    showRectangle(layerId, objId, positions) {
        var material = plotting.fullColor
        var outlineMaterial = new Cesium.PolylineDashMaterialProperty({
            dashLength: 16,
            color: plotting.lineColor
        });
        var rect = Cesium.Rectangle.fromCartesianArray(positions);
        var arr = [rect.west, rect.north, rect.east, rect.north, rect.east, rect.south, rect.west, rect.south, rect.west, rect.north];
        var outlinePositions = Cesium.Cartesian3.fromRadiansArray(arr);
        var bData = {
            layerId: layerId,
            objId: objId,
            shapeType: "Rectangle",
            polyline: {
                positions: outlinePositions,
                clampToGround: true,
                width: 2,
                material: outlineMaterial
            },
            rectangle: {
                coordinates: rect,
                material: material
            }
        };
        return viewer.entities.add(bData);
    }
    // 圆
    showCircle(layerId, objId, positions, tracker) {
        var material = plotting.fullColor;
        var outlineMaterial = new Cesium.PolylineDashMaterialProperty({
            dashLength: 16,
            color: plotting.lineColor
        });
        var radiusMaterial = new Cesium.PolylineDashMaterialProperty({
            dashLength: 16,
            color: Cesium.Color.fromCssColorString('#00f').withAlpha(0.7)
        });
        var pnts = tracker.circleDrawer._computeCirclePolygon(positions);
        var dis = tracker.circleDrawer._computeCircleRadius3D(positions);
        dis = (dis / 1000).toFixed(3);
        var text = dis + "km";
        var bData = {
            layerId: layerId,
            objId: objId,
            shapeType: "Circle",
            position: positions[0],
            label: {
                text: text,
                font: '16px Helvetica',
                fillColor: Cesium.Color.SKYBLUE,
                outlineColor: Cesium.Color.BLACK,
                outlineWidth: 1,
                style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                eyeOffset: new Cesium.ConstantProperty(new Cesium.Cartesian3(0, 0, -9000)),
                pixelOffset: new Cesium.Cartesian2(16, 16)
            },
            billboard: {
                image: "static/images/point.png",
                eyeOffset: new Cesium.ConstantProperty(new Cesium.Cartesian3(0, 0, -500)),
                heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
            },
            polyline: {
                positions: positions,
                clampToGround: true,
                width: 2,
                material: radiusMaterial
            },
            polygon: new Cesium.PolygonGraphics({
                hierarchy: pnts,
                asynchronous: false,
                material: material
            })
        };
        return viewer.entities.add(bData);

        var outlineBdata = {
            layerId: layerId,
            objId: objId,
            shapeType: "Circle",
            polyline: {
                positions: pnts,
                clampToGround: true,
                width: 2,
                material: outlineMaterial
            }
        };
        var outlineEntity = viewer.entities.add(outlineBdata);
    }
    showPoint(layerId, objId, position, text) {
        return viewer.entities.add({
            layerId: layerId,
            objId: objId,
            shapeType: "Point",
            position: position,
            label: {
                text,
                font: '18px "微软雅黑", Arial, Helvetica, sans-serif, Helvetica',
                fillColor: plotting.fullColor,
                outlineColor: Cesium.Color.SKYBLUE,
                outlineWidth: 1,
                style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                disableDepthTestDistance: Number.POSITIVE_INFINITY,
                pixelOffset: new Cesium.Cartesian2(0, 20)
            },
            billboard: {
                image: "static/images/circle_red.png",
                eyeOffset: new Cesium.ConstantProperty(new Cesium.Cartesian3(0, 0, -500)),
                heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
            }
        });
    }
    showBufferLine(layerId, objId, positions, radius, tracker) {
        var buffer = tracker.bufferLineDrawer.computeBufferLine(positions, radius);
        var material = plotting.fullColor;
        var lineMaterial = new Cesium.PolylineDashMaterialProperty({
            dashLength: 16,
            color: plotting.lineColor
        });
        var bData = {
            layerId: layerId,
            objId: objId,
            shapeType: "BufferLine",
            polygon: new Cesium.PolygonGraphics({
                hierarchy: buffer,
                asynchronous: false,
                material: material
            }),
            polyline: {
                positions: positions,
                clampToGround: true,
                width: 2,
                material: lineMaterial
            }
        };
        return viewer.entities.add(bData);
    }
    // 坐标查询
    showPosDistance(layerId, objId, position) {
        var text = this._getMeasureTip(position);
        var bData = {
            layerId: layerId,
            objId: objId,
            shapeType: "PosMeasure",
            position: position,
            label: {
                text: text,
                font: '18px "微软雅黑", Arial, Helvetica, sans-serif, Helvetica',
                fillColor: Cesium.Color.RED,
                outlineColor: Cesium.Color.SKYBLUE,
                outlineWidth: 1,
                style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                disableDepthTestDistance: Number.POSITIVE_INFINITY,
                // pixelOffset:new Cesium.Cartesian2(0,30)    
            },
            billboard: {
                image: "static/images/circle_red.png",
                eyeOffset: new Cesium.ConstantProperty(new Cesium.Cartesian3(0, 0, -500)),
                heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
            }
        };

        return viewer.entities.add(bData);
    }
    _getMeasureTip(cartesian) {
        var pos = this._getLonLat(cartesian);
        if (!pos.alt) {
            pos.alt = "";
        } else {
            pos.alt = pos.alt.toFixed(1);
        }
        pos.lon = pos.lon.toFixed(3);
        pos.lat = pos.lat.toFixed(3);
        var tip = "经度：" + pos.lon + "，纬度：" + pos.lat + "\n 海拔=" + pos.alt + "米";
        return tip;
    }
    _getLonLat(cartesian) {
        var cartographic = viewer.scene.globe.ellipsoid.cartesianToCartographic(cartesian);
        cartographic.height = viewer.scene.globe.getHeight(cartographic);
        var pos = {
            lon: cartographic.longitude,
            lat: cartographic.latitude,
            alt: cartographic.height
        };
        pos.lon = Cesium.Math.toDegrees(pos.lon);
        pos.lat = Cesium.Math.toDegrees(pos.lat);
        return pos;
    }
    showStraightArrow(layerId, objId, positions) {
        var material = plotting.fullColor;
        var outlineMaterial = new Cesium.PolylineDashMaterialProperty({
            dashLength: 16,
            color: plotting.lineColor
        });
        var outlinePositions = [].concat(positions);
        outlinePositions.push(positions[0]);
        var bData = {
            layerId: layerId,
            objId: objId,
            shapeType: "StraightArrow",
            polyline: {
                positions: outlinePositions,
                clampToGround: true,
                width: 2,
                material: outlineMaterial
            },
            polygon: new Cesium.PolygonGraphics({
                hierarchy: positions,
                asynchronous: false,
                material: material
            })
        };
        return viewer.entities.add(bData);
    }
    showAttackArrow(layerId, objId, positions) {
        var material = plotting.fullColor;
        var outlineMaterial = new Cesium.PolylineDashMaterialProperty({
            dashLength: 16,
            color: plotting.lineColor
        });
        var outlinePositions = [].concat(positions);
        outlinePositions.push(positions[0]);
        var bData = {
            layerId: layerId,
            objId: objId,
            shapeType: "AttackArrow",
            polyline: {
                positions: outlinePositions,
                clampToGround: true,
                width: 2,
                material: outlineMaterial
            },
            polygon: new Cesium.PolygonGraphics({
                hierarchy: positions,
                asynchronous: false,
                material: material
            })
        };
        return viewer.entities.add(bData);
    }
    showPincerArrow(layerId, objId, positions) {
        var material = plotting.fullColor;
        var outlineMaterial = new Cesium.PolylineDashMaterialProperty({
            dashLength: 16,
            color: plotting.lineColor
        });
        var outlinePositions = [].concat(positions);
        outlinePositions.push(positions[0]);
        var bData = {
            layerId: layerId,
            objId: objId,
            shapeType: "PincerArrow",
            polyline: {
                positions: outlinePositions,
                clampToGround: true,
                width: 2,
                material: outlineMaterial
            },
            polygon: new Cesium.PolygonGraphics({
                hierarchy: positions,
                asynchronous: false,
                material: material
            })
        };
        return viewer.entities.add(bData);
    }
}